package com.cjhstudy.mall.controller;

import com.cjhstudy.mall.service.IProductService;
import com.cjhstudy.mall.vo.ProductDetailVo;
import com.cjhstudy.mall.vo.ResponseVo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: phil
 * @ProjectName: mall
 * @Date: 2021/12/9
 */
@RestController
public class ProductController {

    @Autowired
    private IProductService productService;

    /**
     * 查询所有的商品信息
     * @RequestParam(required = false,defaultValue = "1") : required = false 对输入不做要求，defaultValue = "1"：默认值是 1
     * @param categoryId 商品id
     * @param pageNum 分页的页数
     * @param pageSize 分页的个数
     * @return 返回商品数量信息
     */
    @GetMapping("/products")
    public ResponseVo<PageInfo> list(@RequestParam(required = false) Integer categoryId,
                                     @RequestParam(required = false,defaultValue = "1") Integer pageNum,
                                     @RequestParam(required = false,defaultValue = "10") Integer pageSize){
        return productService.list(categoryId, pageNum, pageSize);
    }

    /**
     * @PathVariable Integer productId : 在前面这样标注是因为这个是在URL里面携带的参数
     * @param productId 商品id
     * @return 返回商品id的详情
     */
    @GetMapping("/products/{productId}")
    public ResponseVo<ProductDetailVo> detail(@PathVariable Integer productId){
        return productService.detail(productId);
    }

}
